package com.winit.deployZone.repository;

import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
import com.winit.deployZone.model.DeployZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by wangjian on 2017/9/28.
 */
@Component
public class DeployZoneOperations {
    private static Logger logger = LoggerFactory.getLogger(DeployZoneOperations.class);

    @Autowired
    private CassandraOperations cassandraOperations;

    public List<DeployZone> getDeployZone(String deployCode) {
        Select select = QueryBuilder.select().from("uconfig_deploy_zone");
        if (!StringUtils.isEmpty(deployCode)) {
            select.where(QueryBuilder.eq("deploy_code", deployCode));
        }
        List<DeployZone> list = cassandraOperations.select(select, DeployZone.class);
        return list;
    }

}
